package cn.yeziji.forum.controller;

import cn.yeziji.forum.common.ForumResult;
import cn.yeziji.forum.dao.intf.ForumQuestionDao;
import cn.yeziji.forum.dto.question.QuestionDTO;
import cn.yeziji.forum.dto.question.QuestionPagingDTO;
import cn.yeziji.forum.utils.ForumResultUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 论坛问题控制器
 *
 * @author gzkemays
 * @since 2022/11/12 6:05 PM
 */
@RestController
@RequestMapping("/question")
public class ForumQuestionController {
  @Resource ForumQuestionDao questionDao;

  @PostMapping("/submit")
  public ForumResult submit(@RequestBody QuestionDTO dto) {
    questionDao.submit(dto);
    return ForumResultUtils.ok();
  }

  @PostMapping("/adopted")
  public ForumResult adopted(@RequestBody QuestionDTO dto) {
    questionDao.adopted(dto);
    return ForumResultUtils.ok();
  }

  @GetMapping("/list")
  public ForumResult list(QuestionPagingDTO pagingDTO) {
    return ForumResultUtils.ok(questionDao.list(pagingDTO));
  }

  @GetMapping("/get/{id}")
  public ForumResult get(@PathVariable("id") Integer id) {
    return ForumResultUtils.ok(questionDao.getQuestionById(id));
  }
}
